package com.example.wc.logindemo;

import android.app.Application;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;

/**
 * Created by hui on 2017/1/13.
 */

//public class MyApplication extends Application {
//
//    public static RequestQueue sRequestQueue;
//
//    public static RequestQueue getsRequestQueue() {
//        return sRequestQueue;
//    }
//
//    public void OnCreate(){
//        super.onCreate();
//        sRequestQueue= Volley.newRequestQueue(getApplicationContext());
//    }
//}

////首页登录
//                JSONObject params = new JSONObject();
//                try {
//                    params.put("mobile","15736723671");
//                    params.put("password","e10adc3949ba59abbe56e057f20f883e");
////                    params.put("mobile",mUser.getText().toString());
////                    params.put("password",mUsers.getPassword());
//                } catch (JSONException e) {
//                    e.printStackTrace();
//                }
//                JsonObjectRequest jsonObjectRequest = new JsonObjectRequest("http://www.diyerland.com/user/api/login", params,
//                        new Response.Listener<JSONObject>() {
//                            @Override
//                            public void onResponse(JSONObject response) {
//                                if(response == null){
//                                    return;
//                                }
//                                try {
//                                    Integer error = (Integer) response.get("error");
//                                    if(error == 0){
//                                        JSONObject data = response.getJSONObject("data");
//                                        String mobile = data.getString("mobile");
//                                        String accessToken = data.getString("accessToken");
//                                        ACCESS = accessToken;
////                                        Intent i = new Intent(LoginDemoActivity.this, HomepageActivity.class);
//                                        Intent i = new Intent(LoginDemoActivity.this, BlogsListActivity.class);
//                                        startActivity(i);
////                                        Toast.makeText(LoginDemoActivity.this,accessToken,Toast.LENGTH_SHORT).show();
//                                    }
//                                }catch (Exception e){
//
//                                    Toast.makeText(LoginDemoActivity.this,e.getMessage(),Toast.LENGTH_SHORT).show();
//                                }
//                            }
//                        }, new Response.ErrorListener() {
//                    @Override
//                    public void onErrorResponse(VolleyError error) {
//                        Toast.makeText(LoginDemoActivity.this,error.getMessage(),Toast.LENGTH_SHORT).show();
//                    }
//                });
//                Volley.newRequestQueue(LoginDemoActivity.this).add(jsonObjectRequest);


//WriteBlogActivity.class发布博客，对应VolleyRequestDemo->volleyRequestDemo_POST_Add
//JSONObject jsonObject = new JSONObject();
//
//                try {
////                    jsonObject.put("name", "江城子");
////                    jsonObject.put("content", "十年生死两茫茫，不思量，自难忘。");
//                    jsonObject.put("name", mName.getText());
//                    jsonObject.put("content", mContent.getText());
//                } catch (JSONException e) {
//                    e.printStackTrace();
//                }

//                JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(
//                        "http://www.diyerland.com/diyerland/api/blogadd",
//                        jsonObject,
//                        new Response.Listener<JSONObject>() {
//                            @Override
//                            public void onResponse(JSONObject response) {
//
//                                if(response == null)
//                                    return;
//
//                                try {
//                                    Integer error = (Integer) response.get("error");
//                                    if(error == 0) {
////                                        JSONObject data = response.getJSONObject("data");
////                                        String name = data.getString("name");
////                                        String accessToken = data.getString("accessToken");
////                                        Toast.makeText(WriteBlogActivity.this,accessToken,Toast.LENGTH_SHORT).show();
//                                        Log.d("TAG", "发布成功");
//                                        Intent i = new Intent(WriteBlogActivity.this, BlogsListActivity.class);
//                                        startActivity(i);
//                                    }
//
//                                } catch (JSONException e) {
////                                    e.printStackTrace();
//                                    Toast.makeText(WriteBlogActivity.this,e.getMessage(),Toast.LENGTH_SHORT).show();
//                                }
//                            }
//                        },
//                        new Response.ErrorListener() {
//                            @Override
//                            public void onErrorResponse(VolleyError error) {
//                                Toast.makeText(WriteBlogActivity.this,error.getMessage(),Toast.LENGTH_SHORT).show();
//                            }
//                        }
//                ){
//                    @Override
//                    public Map<String, String> getHeaders() throws AuthFailureError{
//                        HashMap<String, String> headers = new HashMap<String, String>();
//                        headers.put("Content-Type", "application/json");
//                        headers.put("accessToken", ACCESS);
//                        return headers;
//                    }
//                };
//                Volley.newRequestQueue(WriteBlogActivity.this).add(jsonObjectRequest);

//BlogsListFragment.class请求get获取博客，对应VolleyRequestDemo->volleyRequestDemo_GET
/*     jsonObjectRequest = new JsonObjectRequest("http://www.diyerland.com/diyerland/api/blogs", null,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {

                        Gson gson = new Gson();
                        responseSave = gson.fromJson(response.toString(), BlogLab.Content.class);
                        Log.d("TAG", responseSave.toString());

                        updateUI();

                        String jsonString = "{\"name\":\"怪盗kidou\",\"content\":24}";
                        Blog blogs = gson.fromJson(jsonString, Blog.class);
                        Log.d("TAG", blogs.getName());
                        Log.d("TAG", response.toString());
                    }
                    private void updateUI() {

                        List<Blog> blogs = responseSave.content;

                        mAdapter = new BlogAdapter(BlogsListFragment.this.getContext(), blogs);
                        mBlogsRecyclerView.setAdapter(mAdapter);
                    }

                }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        Volley.newRequestQueue(BlogsListFragment.this.getContext()).add(jsonObjectRequest);
        */

